clear all
set more off

global path "~/shared_space/dbaharc/BHOR-YugoslavianRefugees/"
qui do "${path}do_files/InitializeGlobals.do"

/********************/
/*** Prepare Data ***/
/********************/
use "${path}data/GermanYUGMigration.dta", clear

/*Costinot et al (2012) measures
use "${path}data/CDKasinh.dta", clear
preserve
keep if iso3=="DEU"
ren xpest_asinh xpest_asinh_DEU
tempfile DEUcdk
save `DEUcdk'
restore
keep if iso3=="YUG"
merge 1:1 product year using `DEUcdk', keep(master matched) nogen
*/

keep if iso3=="YUG"
merge 1:1 iso3 product year using "${path}data/CDKasinh.dta", keep(master matched) nogen

qui do "${path}do_files/InitializeVars.do"

/*CDK measures on LHS cummulative exports, 3 years*/
preserve
egen temp1 = total(xpest) if year>=1988 & year<=1990, by(product)
egen temp2 = total(xpest) if year>=2005 & year<=2007, by(product)
g cumxp = temp1/3 if year==1990
replace cumxp = temp2/3 if year==2005
drop temp1 temp2
g lnxp= log(cumxp)
label var lnxp "$ log(\Phi) $"
g asinhxp = asinh(cumxp)
label var asinhxp "$ asinh(\Phi) $"

foreach v in lnxp asinhxp {
    local lbl`v' : variable label `v'
    eststo, title(`lbl`v''): qui reghdfe `v' c.treat2000#c.$after  if $didsample, $rhsoptions
}
foreach v in lnxp asinhxp {
    local lbl`v' : variable label `v'
    eststo, title(`lbl`v''): qui reghdfe `v'  (c.treat2000#c.$after=c.treatIV#c.$after) if $didsample, $rhsoptions
}
estout, $estout_params_IV_txt mgroups("OLS" "2SLS", $estout_mgroups_ops) 
estout using "${path}tables/DIDMainCumExp_LHSCDK.tex", replace $estout_params_IV $estout_pre $estout_post mgroups("OLS" "2SLS", $estout_mgroups2_ops) 
eststo clear
restore
